﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SqlBuilder
{
    public partial class Loading : Form
    {

        public Loading(int w, int h)
        {
            InitializeComponent();
            this.Width = w;
            this.Height = h;
            this.skinProgressIndicator1.Location = new Point(this.Width / 2-this.skinProgressIndicator1.Width/2, this.Height / 2-this.skinProgressIndicator1.Height/2);
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Pen labelBorderPen;
            SolidBrush labelBackColorBrush;
            Color cl = Color.FromArgb(125, this.BackColor);
            labelBorderPen = new Pen(cl, 0);
            labelBackColorBrush = new SolidBrush(cl);

            base.OnPaint(pe);
            pe.Graphics.DrawRectangle(labelBorderPen, 0, 0, this.Width, this.Height);
            pe.Graphics.FillRectangle(labelBackColorBrush, 0, 0, this.Width, this.Height);
        }
        public static void ShowLayer(Control control, Action action)
        {
            Loading load = new Loading(control.Width, control.Height);
            load.Show(control);
            load.BeginInvoke(new Action(() =>
            {
                try
                {
                    if (action != null)
                    {
                        action();
                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    load.Close();
                    load.Dispose();
                }
            }));
        }
    }
}
